package com.tre.jdevtemplateboot.common.redis.impl;

import com.tre.jdevtemplateboot.common.constant.SysConstantToken;
import com.tre.jdevtemplateboot.common.util.HttpUtils;
import com.tre.jdevtemplateboot.common.util.YamlConfigurerUtil;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: jdev-boot-core
 * @description
 * @author: JDev
 * @create: 2021-08-05 14:36
 **/
public class RedisUserDeviceHeader {

    private RedisUserDeviceHeader(){
    }

    public static String userDeviceHeader(String userId){
        HttpServletRequest  request = HttpUtils.getHttpServletRequest();
        if (request != null) {
            String headerDeviceKey = YamlConfigurerUtil.getStrYmlVal("com.tre.jdev.header-device-key");
            String headerDeviceValue = request.getHeader(headerDeviceKey);
            if (!StringUtils.hasLength(headerDeviceValue)) {
                headerDeviceValue = request.getParameter(headerDeviceKey);
            }
            if (StringUtils.hasLength(headerDeviceValue)) {
                userId = userId + SysConstantToken.USERID_SPLIT_MARKET_DEVICEID+ headerDeviceValue;
            }
        }
        return userId;
    }

}
